unit IntBar;

interface

uses DGLE, DGLE_Types, Engine;

type
  TIntBar = class(TObject)
  private
    pBar: ITexture;
    pBack: ITexture;
    FTop: Integer;
    FLeft: Integer;
    procedure SetLeft(const Value: Integer);
    procedure SetTop(const Value: Integer);
  public
    constructor Create(Left, Top: Integer; TexFileName: AnsiString);
    property Top: Integer read FTop write SetTop;
    property Left: Integer read FLeft write SetLeft;
    destructor Destroy; override;
    procedure Render(Cur, Max: Integer);
    function MouseOver(): Boolean;
  end;


implementation

uses SysUtils;

{ TIntBar }

constructor TIntBar.Create(Left, Top: Integer; TexFileName: AnsiString);
begin
  Self.Top := Top;  
  Self.Left := Left;
  pResMan.Load('Resources\Sprites\Interface\Backbar.png', IEngineBaseObject(pBack), TEXTURE_LOAD_DEFAULT_2D);
  pResMan.Load(PAnsiChar('Resources\Sprites\Interface\' + TexFileName), IEngineBaseObject(pBar), TEXTURE_LOAD_DEFAULT_2D);
end;

destructor TIntBar.Destroy;
begin
  pBar := nil;
  pBack := nil;
  inherited;
end;

function TIntBar.MouseOver: Boolean;
begin
  Result := (MousePos.X > Left) and (MousePos.X < Left + 202) and (MousePos.Y > Top) and (MousePos.Y < Top + 18);
end;

procedure TIntBar.Render(Cur, Max: Integer);
var
  W, H: Cardinal;
  P: PAnsiChar;
begin
  pRender2D.DrawTexture(pBack, Point2(Left, Top), Point2(202, 18));
  pRender2D.DrawTexture(pBar, Point2(Left + 1, Top + 1), Point2(BarWidth(Cur, Max, 200), 16));
  if MouseOver then
  begin
    P := StrToPAChar(IntToStr(Cur) + '/' + IntToStr(Max));
    pFont11.GetTextDimensions(P, W, H);
    pFont11.Draw2DSimple(Left + (101 - (Integer(W) div 2)), Top + (8 - (Integer(H) div 2)), P, Color4);
  end;
end;

procedure TIntBar.SetLeft(const Value: Integer);
begin
  FLeft := Value;
end;

procedure TIntBar.SetTop(const Value: Integer);
begin
  FTop := Value;
end;

end.
